package com.zytlifeservice.repository;

import com.zytlifeservice.domain.User;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;

/**
 * Created by MJS on 2017/4/22.
 */
public interface UserRepository extends JpaRepository<User, Long> {
    public User findByName(String name);

    public User findByMobile(String mobile);

    public User findByMobileAndPassword(String mobile, String password);

    public int deleteByMobile(String mobile);

    Integer getTopByUserIntegral(Long userId);


    //更新个人积分
    @Modifying(clearAutomatically = true)
    @Query(value = "update user set user_integral=?1 where user_id=?2", nativeQuery = true)
    public void updateIntegral(Integer userIntegral, Long userId);

    /*
    查询用户是否存在
     */
    @Query(value = "select count (userId) from User  where userId=?1")
    int queryIfExit(long userId);
}
